//2.
const jwt = require('jsonwebtoken')
secret = 'rfhjsdkfghjdkshgjkds45783567483'
const JWT = {
    generate(data, expires) {
        return jwt.sign(data, secret, { expiresIn: expires })
    },
    //7.
    verify(req, res, next) {
        const {token} = req.cookies
        return jwt.verify(token, secret, (err, result) => {
            if (err) {
                res.send('登录后即可操作')
            } else {
                //11.
                req.body.username=result.username
                
                next()
            }
        })
    }
}

module.exports = JWT